<template>
  <div class="app-container">
<!--    隐藏域 记录id-->
    <input type="hidden" v-model="card.id"/>
    <el-form ref="form" :model="card" label-width="120px">
      <el-form-item label="借阅卡编号">
        <el-input v-model="card.sid" />
      </el-form-item>
      <el-form-item label="学生姓名">
        <el-input v-model="student.sname" />
      </el-form-item>
      <el-form-item label="卡状态">
        <el-input v-model="card.state" />
      </el-form-item>
      <el-form-item label="剩余借书数量">
        <el-input v-model="card.number" />
      </el-form-item>
      <el-form-item label="办卡时间">
        <el-date-picker
          v-model="card.date"
          type="date"
          placeholder="请选择时间"
          value-format="yyyy-MM-dd"
          style="width: 100%"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary"  @click="onSubmit">修改信息</el-button>
        <el-button @click="onCancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import request from '@/utils/request'
export default {
  data() {
    return {
      card: {
        sid:0,
        sname: '',
        state: '',
        number: '',
        date: ''
      },
      student:{
        sname:''
      }
    }
  },
  mounted() {
    this.card=this.$store.state.user.card;
  },
  methods: {
    onSubmit() {
      request({
        url: "/library/card/selectIdByName.do?name=" + this.card.sname,
        method: "GET"
      }).then(res => {
        if (res.code == 0) {
          this.card.sid = res.data.id;
              request({
                url: "/library/record/update.do",
                method: "POST",
                data: this.record
              }).then(res => {
                if (res.code == 0) {
                  //跳转到列表页面
                  this.$router.push("/recordlist");
                }
              });
            }
          })
        }
  },

    onCancel() {
      this.$message({
        message: 'cancel!',
        type: 'warning'
      });
      this.$router.push("/cardlist");
    }
}
</script>

<style scoped>
.line{
  text-align: center;
}
</style>

